from pyecharts.charts import Bar, Line, Grid, Page
from pyecharts.components import Table
from pyecharts.options import ComponentTitleOpts
import pyecharts.options as opts

def draw_bar_with_multiple(xasix, yaxis_dict, title, height):
    bar = Bar(init_opts=opts.InitOpts(width='100%',height=height, bg_color='#FFFFFF'))
    bar.add_xaxis(xasix)
    for key, value in yaxis_dict.items():
        bar.add_yaxis(key, value)
    bar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 定义交互
    tooltip_opts = opts.TooltipOpts(is_show=True, trigger='axis', trigger_on = "mousemove | click", axis_pointer_type='line')
    # 定义标题
    title_opts = opts.TitleOpts(title=title)
    # 设置配置项
    bar.set_global_opts(
        tooltip_opts = tooltip_opts, 
        title_opts=title_opts, 
    )
    return bar

def draw_line_with_multiple(xaxis, yaxis_dict, title, height):
    # 设置画布大小
    line = Line(init_opts=opts.InitOpts(width='100%',height=height, bg_color='#FFFFFF'))
    # 设置x轴数据
    line.add_xaxis(xaxis) # 横坐标必须为str类型
    # 设置y轴数据
    min_y = 1000000
    max_y = -1000000
    for key,value in yaxis_dict.items():
        line.add_yaxis(series_name=key, y_axis=value, is_symbol_show=False)
        min_y = min(value) if min(value) < min_y else min_y
        max_y = max(value) if max(value) > max_y else max_y
    # 定义交互
    tooltip_opts = opts.TooltipOpts(is_show=True, trigger='axis', trigger_on = "mousemove | click", axis_pointer_type='line')
    # 定义标题
    title_opts = opts.TitleOpts(title=title)
    # 设置配置项
    line.set_global_opts(
        tooltip_opts = tooltip_opts, 
        title_opts=title_opts, 
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
                min_=min_y,
                max_=max_y,
        ),
    )
    return line